from sqlalchemy.ext.asyncio import AsyncSession

from src.infrastructure.db import repositories as repo
from src.infrastructure.db.uow.base import SQLAlchemyBaseUoW


class SQLAlchemyUoW(SQLAlchemyBaseUoW):
    def __init__(
        self,
        *,
        session: AsyncSession,
        user_repo: repo.UserRepoImpl,
        user_reader: repo.UserReaderImpl,
        order_reader: repo.OrderReaderImpl,
        order_repo: repo.OrderRepoImpl,
        proxy_reader: repo.ProxyReaderImpl,
        proxy_repo: repo.ProxyRepoImpl,
        category_reader: repo.CategoryReaderImpl,
        bot_settings_reader: repo.BotSettingsReaderImpl,
        server_reader: repo.ServerReaderImpl,
    ) -> None:
        self.user_repo = user_repo
        self.user_reader = user_reader
        self.order_reader = order_reader
        self.order_repo = order_repo
        self.proxy_reader = proxy_reader
        self.proxy_repo = proxy_repo
        self.category_reader = category_reader
        self.bot_settings_reader = bot_settings_reader
        self.server_reader = server_reader

        super().__init__(session=session)


def build_uow(session: AsyncSession):
    return SQLAlchemyUoW(
        session=session,
        user_repo=repo.UserRepoImpl(session),
        user_reader=repo.UserReaderImpl(session),
        order_reader=repo.OrderReaderImpl(session),
        order_repo=repo.OrderRepoImpl(session),
        proxy_reader=repo.ProxyReaderImpl(session),
        proxy_repo=repo.ProxyRepoImpl(session),
        category_reader=repo.CategoryReaderImpl(session),
        bot_settings_reader=repo.BotSettingsReaderImpl(session),
        server_reader=repo.ServerReaderImpl(session),
    )
